/*
* @Author: MR.Wang
* @Date:   2017-06-30 18:39:49
* @Last Modified by:   MR.Wang
* @Last Modified time: 2017-06-30 18:50:39
*/

'use strict'
import originJsonp from 'jsonp'

function jsonp(url, data, option) {
  url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
  return new Promise((resolve, reject) => {
    originJsonp(url, option, (err, data) => {
      if (!err) {
        resolve(data)
      } else {
        reject(err)
      }
    })
  })
}

function param(data) {
  let url = ''
  for (var k in data) {
    let value = data[k] !== undefined ? data[k] : ''
    url += `&${k}=${encodeURIComponent(value)}`
  }
  return url ? url.substring(1) : ''
}

export function getWechatShare(link) {
  const url = window._HOST_CONDIG_LIST.mine_host+ '/common/jssdk?url=' + link.link + '&callback=?'
  const data = ''
  // const data = Object.assign({}, {
  //   platform: 'h5',
  //   uin: 0,
  //   needNewCode: 1
  // })

  return jsonp(url, data)
}
